/*
 * Created on 2006-2-10
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.hitrust.gs.action;

import java.util.ArrayList;

import system.LoginContext;

import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.bean.GSDictionaryBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSUserMenuInfoBean;
import com.hitrust.gs.business.*;
import com.hitrust.gs.dao.GSDictionaryDAO;

import framework.core.ConstDefine;
/**
 * @author simonyi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GSOrderInputAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        
//        GSOperatorBean operatorBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        
//        GSOrgProcessor processer = new GSOrgProcessor ();
//        //if(aForm.getSession().getAttribute("organdaddr") == null){
//            ArrayList ary = processer.getSubOrgAndInfo(operatorBean.getGs_oper_org_id());
//            aForm.getRequest().setAttribute("organdaddr",ary);
//        //}
//         
//        GSOperatorProcessor oproc = new GSOperatorProcessor();
//        ArrayList provilege = oproc.getOperPrivilege(operatorBean.getGs_oper_id());
        LoginContext context=(LoginContext) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        //取得采购自己级下属采购单位
        GSUniteGwProcessor unitePro=new GSUniteGwProcessor();
        ArrayList list= unitePro.getWareHouseLevelName(context.getLoginWarehouseCode(),context.getLoginWarehouseCode());
        aForm.getRequest().setAttribute("wareHouse", list);
        //取得当前用户功能权限
        ArrayList menuInfoList=unitePro.getUserMenuInfo(context.getLoginUserId());
        boolean isFirstExist = false;	//初审
        boolean isReviewExist = false;	//复审
        boolean isCommitExist = false;	//提交申购
        boolean isShenWoExist = false;	//申沃零配件采购
        
        for(int i=0;i<menuInfoList.size();i++){
            GSUserMenuInfoBean mbean=(GSUserMenuInfoBean) menuInfoList.get(i);
            if(1102==mbean.getMenu_code()) isFirstExist = true;
            if(1103==mbean.getMenu_code()) isReviewExist = true;
            if(1104==mbean.getMenu_code()) isCommitExist = true;
            if(1109==mbean.getMenu_code()) isShenWoExist = true;
        }
        if(isFirstExist && isReviewExist){
            aForm.getRequest().setAttribute("AUDITNEED","true");
        }else{
            aForm.getRequest().setAttribute("AUDITNEED","false");
        }
        //有直接提交申购功能
        if (isCommitExist)
        	aForm.getRequest().setAttribute("isCommitExist", "true");
        else
        	aForm.getRequest().setAttribute("isCommitExist", "false");        		
        //申沃零配件采购
        if (isShenWoExist)
        	aForm.getRequest().setAttribute("isShenWoExist", "true");
        else
        	aForm.getRequest().setAttribute("isShenWoExist", "false");
        
        ArrayList bcList = GSBaseManager.getAllBalanceCategory();
        aForm.getRequest().setAttribute("balancecategory",bcList);
        
        //配送方式
        GSDictionaryDAO dictionary = new GSDictionaryDAO();
        ArrayList delivermodeList = dictionary.queryByParentId(GSDictionaryBean.DeliverMode);
        aForm.getRequest().setAttribute("deliverModeList", delivermodeList);
        
        //结算方式
        ArrayList balanceModeList = dictionary.queryByParentId(GSDictionaryBean.BalanceMode);
        aForm.getRequest().setAttribute("balanceModeList", balanceModeList);
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }
}
